#include "comm.hpp"
Init init;
int main()
{
    // 1.通过路径得到唯一的k值
    key_t k = ftok(PATH_NAME, PERMISSIONS);
    assert(k != -1);
    Log("创建k值成功", Debug) << "" << endl;
    // 2.创建共享内存
    int shmid = shmget(k, SIZE, IPC_CREAT | IPC_EXCL | 0666);
    assert(shmid != -1);
    Log("创建共享内存成功", Debug) << endl;
    // 3.打开共享内存
    char *shmaddr = (char *)shmat(shmid, nullptr, 0);
    Log("打开共享内存成功", Debug) << endl;

    // 开始通信
        int fd = openFIFO(FIFO_NAME, O_RDONLY);

    while (true)
    {
        Wait(fd);

        printf("%s\n", shmaddr);
        if(strcmp(shmaddr, "quit") == 0 ) break;
    }

    // 4.指定共享内存从地址空间去除挂接
    int n = shmdt(shmaddr);
    assert(n != -1);
    Log("去挂接共享内存成功", Debug) << endl;
    // 5.删除共享内存
    n = shmctl(shmid, IPC_RMID, nullptr);
    assert(n != -1);
    Log("删除共享内存成功", Debug) << endl;

    CloseFD(fd);
    return 0;
}